export function setLocalStorage(key, value) {
  return localStorage.setItem('okr-web' + '-' + key, JSON.stringify(value));
}

export function getLocalStorage(key) {
  if (localStorage.getItem('okr-web' + '-' + key) !== 'undefined') {
    return JSON.parse(localStorage.getItem('okr-web' + '-' + key));
  }
}

export function removeLocalStorage(key) {
  return localStorage.removeItem('okr-web' + '-' + key);
}

export function getDay(day) {
  var today = new Date();
  var milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
  today.setTime(milliseconds);
  var tMonth = today.getMonth();
  var tDate = today.getDate();
  tMonth = doHandleMonth(tMonth + 1);
  tDate = doHandleMonth(tDate);
  return tMonth + '月' + tDate + '日';
}

function doHandleMonth(month) {
  var m = month;
  if (month.toString().length == 1) {
    m = '0' + month;
  }
  return m;
}

//错误日志上报
export function logOperate(params) {
  var args = '';
  for (var i in params) {
    if (args != '') {
      args += '&';
    }
    args += i + '=' + encodeURIComponent(params[i]);
  }
  var img = new Image(1, 1);
  img.src = '/api/log.gif?' + args;
}
